var addressModule = (function (Vue) {
  new Vue({
    el: '#address',
    data: {
      limitNum: 3,
      addressList: [],
      choosedId: -1,
      isTransportDet: 1
    },
    mounted: function () {
      this.getAddressList();
    },
    computed: {
      showList () {
        return this.addressList.slice(0, this.limitNum)
      }
    },
    methods: {
      getAddressList () {
        var _this = this;
        this.$http.get('./data/address.json').then(function (response) {
          var res = response.data;
          if (res.status == 0) {
            _this.addressList = res.result;
          }
        })
      },
      showAll () {
        this.limitNum = this.limitNum === this.addressList.length ? 3: this.addressList.length;
      },
      chooseCart (id) {
        this.choosedId = id;
      },
      setDefault (list) {
        this.addressList.forEach( function(item) {
          if (item.addressId == list.addressId) {
            item.isDefault = true;
          }else {
            item.isDefault = false;
          }
        });
      },
      setDefaultTransport (value) {
        this.isTransportDet = value
      }
    }
  })
})(Vue);